package com.itfreer.data.metadata;

import javax.persistence.EntityManager;

import org.springframework.stereotype.Component;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;

import com.itfreer.data.metadata.dao.DefaultDictionaryDao;
import com.itfreer.data.metadata.entity.DataDictionaryEntity;
import com.itfreer.form.api.JdbcBaseDaoImp;

/**
 * 定义字典服务
 */
@Component("JdbcDefaultDictionaryDao")
public class JdbcDefaultDictionaryDao extends JdbcBaseDaoImp<DataDictionaryEntity> implements DefaultDictionaryDao {

	public JdbcDefaultDictionaryDao(EntityManager entityManager) {
		super(DataDictionaryEntity.class, entityManager);
	}

	/**
	 * 删除实体
	 * 
	 * @param guid
	 *            唯一值
	 * @throws IllegalAccessException
	 * @throws InstantiationException
	 */
	public void deleteEx(String dn, String guid) {
		// 配置事务策略
		DefaultTransactionDefinition def = new DefaultTransactionDefinition();
		def.setName("planOne-transaction");
		def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
		// 设置状态点
		TransactionStatus status = transactionManager.getTransaction(def);
		try {
			DataDictionaryEntity jEntity = new DataDictionaryEntity();
			jEntity.setId(guid);
			jEntity.setDicName(dn);
			em.remove(jEntity);
			transactionManager.commit(status);
		} catch (Exception e) {
			transactionManager.rollback(status);
			throw e;
		}
	}
}